/**
 * 
 */
package org.statewalker.parser.wiki.tokenizer.block;

import org.statewalker.tokenizer.CharStream;
import org.statewalker.tokenizer.StreamToken;
import org.statewalker.tokenizer.CharStream.Pointer;
import org.statewalker.tokenizer.base.SequenceTokenizer;

public class DocumentTokenizer extends SequenceTokenizer {

    private boolean fOpen;

    public DocumentTokenizer(String key, boolean open) {
        super(key, open ? "(((" : ")))");
        fOpen = open;
    }

    @Override
    protected StreamToken newToken(Pointer begin, Pointer end, String str) {
        return new StreamToken(fKey, fOpen, !fOpen, begin, end, str);
    }

    @Override
    public StreamToken read(CharStream stream) {
        StreamToken token = super.read(stream);
        if (token != null) {
            stream.markBeginContext();
        }
        return token;
    }
}